package ztttt1;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<Card> deck = createDeck();
        System.out.println("洗牌前:");
        for(int i = 0;i < deck.size();i++){
            System.out.print(deck.get(i).toString() + " ");
            if((i + 1) % 13 == 0){
                System.out.println();
            }
        }
        deck = sortDeck(deck);
        System.out.println("洗牌后:");
        for(int i = 0;i < deck.size();i++){
            System.out.print(deck.get(i).toString() + " ");
            if((i + 1) % 13 == 0){
                System.out.println();
            }
        }
        //创建4个玩家
        ArrayList<ArrayList<Card>> hands = new ArrayList<>();
        for(int i = 0;i < 4;i++){
            ArrayList<Card> cards = new ArrayList<>();
            hands.add(cards);
        }
        //为4个玩家分发手牌(13张)
        for(int i = 0;i < 13;i++){
            for (int j = 0; j < 4; j++) {
                Card card = deck.get(i * 3 + j);
                hands.get(j).add(card);
            }
        }
        System.out.println("4个玩家的手牌:");
        for(int i = 0;i < 4;i++){
            Collections.sort(hands.get(i));
            System.out.println(hands.get(i));
        }
    }
    //1.创建牌
    public static ArrayList<Card> createDeck(){
        ArrayList<Card> Deck = new ArrayList<>();
        String[] tu = {"♥","♦","♠","♣"};
        for (String tu0:tu) {
            for(int i = 2;i <= 10;i++){
                Card card = new Card(tu0 , "" + i);
                Deck.add(card);
            }
            Card card0 = new Card(tu0,"J");
            Card card1 = new Card(tu0,"Q");
            Card card2 = new Card(tu0,"K");
            Card card3 = new Card(tu0,"A");
            Deck.add(card0);
            Deck.add(card1);
            Deck.add(card2);
            Deck.add(card3);
        }
        return Deck;
    }
    //2.洗牌
    public static ArrayList<Card> sortDeck(ArrayList<Card> deck0){
        Random random = new Random();
        for(int i = 0;i < deck0.size();i++){
            int j = random.nextInt(deck0.size());
            Card card = new Card(deck0.get(i).getColor(),deck0.get(i).getNum());
            deck0.set(i,deck0.get(j));
            deck0.set(j,card);
        }
        return deck0;
    }
}
/*public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        ArrayList<Integer> arr = new ArrayList<>();
        //1.ArrayList的添加元素
        arr.add(10);
        arr.add(20);
        arr.add(15);
        arr.add(5);
        //2.ArrayList的排序
        //Comparator.naturalOrder() 为指定元素以自然顺序(升序)排序
        arr.sort(Comparator.naturalOrder());
        //Comparator.reverseOrder() 对元素进行(降序)排列的方法
        arr.sort(Comparator.reverseOrder());
        //3.ArrayList下标修改元素
        arr.set(0,1);
        int num = arr.get(0); //1
        //4.获取长度
        int len = arr.size();
        //5.删除元素
        arr.remove(1);
        //6.查询
        if(arr.contains(10)){
            System.out.println("10的下标是:" + arr.indexOf(10));
        }else {
            System.out.println("找不到10");
        }
        //7.subList获取到顺序表中的子表
        List<Integer> a0 = arr.subList(0,2);
        //subList(0,2)为左闭右开[ )
        System.out.println("arr的子表[0,2)为: " + a0);
        System.out.println("arr = " + arr);
        System.out.println("arr 的长度为: " + arr.size());
        //8.clear清空顺序表
        arr.clear();
    }
}*/

